//
// Created by 郝正辉 on 2020/12/6.
//

#include <stdint.h>
#include "compress_test.h"
#include <stdio.h>
#include <stdlib.h>

int8_t compress_test(unsigned char *data,
                     int size,
                     int (*compare)(const unsigned char *original, unsigned char **compressed, int size),
                     int (*uncompress)(const unsigned char *compressed, unsigned char **original)
) {
    printf("data:%s\nsize:%d\n", data, size);
    printf("short:%d\n", sizeof(short));
    unsigned char *compressed;
    int size_comp;
    if ((size_comp = compare(data, &compressed, size)) < 0) {
        printf("compress error.\n");
        return -1;
    }
    printf("compress_size:%d\n", size_comp);
    unsigned char *original;
    int size_orig;
    if ((size_orig = uncompress(compressed, &original)) != size) {
        printf("uncompress error,uncompress_size:%d\n", size_orig);
//        return -1;
    }
    free(compressed);
    printf("orig:%s\nsize:%d\n", original, size_orig);
    free(original);
    if (size_orig == size) {
        printf("OK!!\n");
        return 0;
    } else {
        printf("ERROR!!\n");
        return -1;
    }
}
